package com.sale.succ.system.ftp;

import java.io.IOException;
import java.util.Properties;

import com.sale.succ.utils.SystemConstants;
import com.sale.succ.utils.TraderHelper;

public class FTPProcessing {
	FTPClient ftp;
	
	public FTPProcessing(String login, String pass) throws FTPException, IOException {
		String ftpIP = null;
		Properties currentProperties = TraderHelper.getSystemProps();
		if (currentProperties.getProperty(SystemConstants.FTP_SERVER_IP) != null) {
			ftpIP = currentProperties.getProperty(SystemConstants.FTP_SERVER_IP);
		}
		ftp = new FTPClient(ftpIP);
		ftp.login(login, pass);
		ftp.setType(FTPTransferType.BINARY);
	}
	
	public FTPClient getFTPClient(){
		return ftp;
	}
	
	public boolean setLocalDir(String localDir){
		ftp.setLocalDir(localDir);
    	return Boolean.TRUE;
	}
	
	public boolean ftpUpload(String fileName) throws IOException, FTPException{
		ftp.uploadFile(fileName);
    	return Boolean.TRUE;
	}
	
	public boolean ftpDownload(String fileName) throws IOException, FTPException{
		ftp.downloadFile(fileName);
    	return Boolean.TRUE;
	}
	
	public void closeFTP() throws IOException, FTPException{
		ftp.quit();
	}
	
}
